package warbots.entities.actions;


import java.awt.Point;
import java.util.Set;

import warbots.entities.units.Unit;
import warbots.gameplay.Cell;
import warbots.gameplay.Map;


/**
 * @author Ido Adler.
 */
public class MoveAndHitAction extends HitAction
{
    MoveAction _move;
    
    /**
     * TODO: description
     * 
     * @param parent
     * @param name
     */
    public MoveAndHitAction(final Unit parent, final String name)
    {
        super(parent, name);
        _move = new MoveAction(parent, name);
        _price += _parent.getSpeed();
    }
    
    /**
     * @see warbots.entities.actions.HitAction#execute(warbots.gameplay.Map,
     *      java.awt.Point)
     */
    @Override
    public boolean execute(final Map world, final Point target)
    {
        if (super.execute(world, target))
            return true;
        
        Set<Cell> cells = world.cellsInRadius(world._board[target.x][target.y], 1);
        for (Cell cell : cells)
        {
            if (_move.execute(world, world.find(cell)))
            {
                super.execute(world, target);
                return true;
            }
        }
        
        return false;
    }
}
